//
//  ZRootTabBarViewController.m
//  BestPurchase
//
//  Created by ZSMAC on 2018/10/9.
//  Copyright © 2018年 张帅. All rights reserved.
//

#import "ZRootTabBarViewController.h"
#import "ZNavRootViewController.h"
#import "HomeViewController.h"
#import "IdenticalCityController.h"
#import "MessageViewController.h"
#import "MyViewController.h"
#import "StoreViewController.h"
#import "loginViewController.h"
@interface ZRootTabBarViewController ()

@end

@implementation ZRootTabBarViewController
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    BmobUser *user = [BmobUser currentUser];
    if (!user) {
        loginViewController * vc = [[loginViewController alloc] init];
        UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:vc];
        UIViewController * currentVC = [MPublicManager sharedPublicManager].currentControllr;
        [currentVC  presentViewController:nav animated:YES completion:nil];
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    if (Merchants == 0) {//普通版
        [self normalVersionSet];
    } else {
        //商家版
        [self merchantsVersion];
    }
}
- (void)merchantsVersion {
    MessageViewController * MessageVC = [[MessageViewController alloc] init];
    ZNavRootViewController * MessageNav = [[ZNavRootViewController alloc] initWithRootViewController:MessageVC];
    MessageNav.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"消息" image:[UIImage imageNamed:@"message"] selectedImage:[UIImage imageNamed:@"message_selected"]];
    
    StoreViewController * GoodsReleasedVC = [[StoreViewController alloc] init];
    ZNavRootViewController * GoodsReleasedVCNav = [[ZNavRootViewController alloc] initWithRootViewController:GoodsReleasedVC];
    GoodsReleasedVCNav.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"店铺" image:[UIImage imageNamed:@"tab_icon_circle_default"] selectedImage:[UIImage imageNamed:@"tab_icon_circle_selected"]];
    
    MyViewController * MyVC = [[MyViewController alloc] init];
    ZNavRootViewController * MyNav = [[ZNavRootViewController alloc] initWithRootViewController:MyVC];
    MyNav.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"我的" image:[UIImage imageNamed:@"tab_icon_circle_default"] selectedImage:[UIImage imageNamed:@"tab_icon_circle_selected"]];
 
    self.viewControllers=@[MessageNav,GoodsReleasedVCNav,MyNav,];
    
}
#pragma mark
- (void)normalVersionSet {
    HomeViewController * homeVC = [[HomeViewController alloc] init];
    ZNavRootViewController * HomeNav = [[ZNavRootViewController alloc] initWithRootViewController:homeVC];
    HomeNav.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"首页" image:[UIImage imageNamed:@"tab_icon_circle_default"] selectedImage:[UIImage imageNamed:@"tab_icon_circle_selected"]];
    
    IdenticalCityController * IdenticalCityVC = [[IdenticalCityController alloc] init];
    ZNavRootViewController * IdenticalCityNav = [[ZNavRootViewController alloc] initWithRootViewController:IdenticalCityVC];
    IdenticalCityNav.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"同城" image:[UIImage imageNamed:@"city"] selectedImage:[UIImage imageNamed:@"city_selected"]];
    
    MessageViewController * MessageVC = [[MessageViewController alloc] init];
    ZNavRootViewController * MessageNav = [[ZNavRootViewController alloc] initWithRootViewController:MessageVC];
    MessageNav.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"消息" image:[UIImage imageNamed:@"message"] selectedImage:[UIImage imageNamed:@"message_selected"]];
    
    MyViewController * MyVC = [[MyViewController alloc] init];
    ZNavRootViewController * MyNav = [[ZNavRootViewController alloc] initWithRootViewController:MyVC];
    MyNav.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"我的" image:[UIImage imageNamed:@"tab_icon_circle_default"] selectedImage:[UIImage imageNamed:@"tab_icon_circle_selected"]];
    
    self.viewControllers=@[HomeNav,IdenticalCityNav,MessageNav,MyNav,];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
